<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>react初体验</title>
    <!-- 加载react必须的两个js库 -->
    <script src="./js/react/react18.2.0.js"></script>
    <script src="./js/react/react-dom18.2.0.js"></script>
    <!-- 推荐react使用jsx -->
    <script src="./js/react/jsx/babel.js"></script>
    
    <!-- 这里写react组件样式代码 -->
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #root{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .button{
            color: red;
            transition: all .3s;
        }
    </style>
</head>
<body>
    <!-- APP入口标签 -->
    <div id="root"></div>

    <!-- 在这里写你的js代码 type="text/babel":用来解析jsx-->
    <script type="text/babel">

        // 新增一个react组件（组件名称必须大写开头）
        const MyButton = () => {

            // 定义react组件状态
            const [liked, setLiked] = React.useState(false);
            const [heights, setHeights] = React.useState(30);

            // 使用useEffect同步更改按钮的高度
            React.useEffect(() => {
                setHeights(liked?60:30)
            }, [liked])

            // 返回的jsx语法模板
            return (
                <button className="button" style={{height: heights+'px'}} onClick={() => { setLiked(!liked) }}>
                    {String(liked)}
                </button>
            )
        }

        // 顶层react组件，app入口
        const domContainer = document.getElementById('root');
        const root = ReactDOM.createRoot(domContainer);
        root.render(<MyButton />)

    </script>
</body>
</html>